package cn.uncode.dal.springboot.config;

import javax.sql.DataSource;

import org.apache.commons.dbcp2.BasicDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;


@ConfigurationProperties(prefix = "uncode.dal.datasource.standby",ignoreInvalidFields = false)
public class StandbyDataSourceConfig extends DataSourceProperties{
	
	
	private String url;
	private String username;
	private String password;
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	public void valueOf(ClusterDataSourceProperties dataSource) {
		this.setUsername(dataSource.getUsername());
		this.setDriverClassName(dataSource.getDriverClassName());
		this.setInitialSize(dataSource.getInitialSize());
		this.setMaxIdle(dataSource.getMaxIdle());
		this.setMaxPoolPreparedStatementPerConnectionSize(dataSource.getMaxPoolPreparedStatementPerConnectionSize());
		this.setMaxTotal(dataSource.getMaxTotal());
		this.setMaxWaitMillis(dataSource.getMaxWaitMillis());
		this.setMinIdle(dataSource.getMinIdle());
		this.setPassword(dataSource.getPassword());
		this.setRemoveAbandonedTimeout(dataSource.getRemoveAbandonedTimeout());
		this.setUrl(dataSource.getUrl());
		this.setValidationQuery(dataSource.getValidationQuery());
	}
	
	public DataSource build() {
		BasicDataSource basicDataSource = new BasicDataSource();
		basicDataSource.setUrl(url);
		basicDataSource.setUsername(username);
		basicDataSource.setPassword(password);
		coinfig(basicDataSource);
		return basicDataSource;
	}

	
	

}
